import wepy from 'wepy';
const KEY = 'GOODS';

const addGoods = (goods) => {
  const localStorage = wepy.getStorageSync(KEY) || {};
  if (localStorage[goods.goods_id]) {
    localStorage[goods.goods_id] += goods.goods_number;
  } else {
    localStorage[goods.goods_id] = goods.goods_number;
  }
  wepy.setStorageSync(KEY, localStorage)
};


const updateGoods = (goods)=>{
    const localStorage = wepy.getStorageSync(KEY) || {};
    localStorage[goods.goods_id] = goods.goods_number;
    wepy.setStorageSync(KEY, localStorage)
}

const deleteGoods = (goods_id)=>{
    const localStorage = wepy.getStorageSync(KEY) || {}; 
    delete localStorage[goods_id]
    wepy.setStorageSync(KEY, localStorage)
}

export {addGoods,updateGoods,deleteGoods}